package com.lzy.cloud.order.controller;

import com.lzy.cloud.order.dtos.OrderAssessContentDto;
import com.lzy.cloud.order.request.OrderAssessContentRequest;
import com.lzy.cloud.order.response.OrderAssessContentResponse;
import com.lzy.cloud.order.service.OrderAssessContentService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单评论内容
 * Created by WIN7 on 2018/6/6.
 */
@RestController
@RequestMapping("/order/assess/content")
public class OrderAssessContentController {

    @Autowired
    private OrderAssessContentService orderAssessContentService;

    /**
     * 根据评论id查询订单评论内容
     * @param assessId
     * @return
     */
    @RequestMapping(value = "/find/by/assess/id/{assessId}",method = RequestMethod.GET)
    public Result queryListByAssessId(@PathVariable("assessId") Long assessId) {
        Ensure.that(assessId).isNotNull("00010003");
        List<OrderAssessContentDto> list = orderAssessContentService.queryListByAssessId(assessId);
        return new Result(DozerUtils.map(list, OrderAssessContentResponse.class));
    }

    /**
     * 新增订单评论内容
     * @param request
     * @return
     */
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public Result create(@RequestBody OrderAssessContentRequest request) {
        Ensure.that(request).isNotNull("00000002");
        Long id = orderAssessContentService.create(DozerUtils.map(request, OrderAssessContentDto.class));
        Ensure.that(id).isGt(0, "00120001");
        return new Result(id);
    }
}
